package com.zy.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import java.util.Properties;

/**
 * Created by ab804 on 2015/9/24 0024.
 */
@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@ImportResource("classpath:/consumer.xml")
@ComponentScan(basePackages = {"com.zy.controller"})
public class Boot {
    public static void main(String[] args) {
        SpringApplication.run(Boot.class, args);
    }


    @Bean
    public FreeMarkerViewResolver viewResolver() {
        FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
        viewResolver.setCache(false);
        viewResolver.setPrefix("");
        viewResolver.setSuffix(".ftl");
        viewResolver.setContentType("text/html;charset=utf-8");
        viewResolver.setViewClass(CustomFreemarkerView.class);
        return viewResolver;
    }

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer() {
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        configurer.setTemplateLoaderPath("classpath:/templates/");
        configurer.setDefaultEncoding("utf-8");
        Properties props = new Properties();
        props.setProperty("number_format", "0.##");
        configurer.setFreemarkerSettings(props);
        return configurer;
    }


}
